package com.quanxi.qxaimain.dao.forVue;

import com.quanxi.qxaimain.common.datasource.datasourceAOP.annotation.DataSource;
import com.quanxi.qxaimain.common.datasource.datasourceAOP.enums.DataSourceEnum;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author lyx
 * @create 2023/2/20 16:09
 */

@Component
public interface DMLMapper {

    @DataSource(DataSourceEnum.DB4)
    @Select("${sqlStr}")
    List<LinkedHashMap<String, Object>> exec_sql4(@Param(value = "sqlStr") String sqlStr);



    @DataSource(DataSourceEnum.DB4)
    @Select("${sqlStr}")
    List<Map<String, Object>> exec_sql_listmap4(@Param(value = "sqlStr") String sqlStr);

    @DataSource(DataSourceEnum.DB1)
    @Select("${sqlStr}")
    List<LinkedHashMap<String, Object>> exec_sql1(@Param(value = "sqlStr") String sqlStr);





    @DataSource(DataSourceEnum.DB4)
    @Insert("<script>" +

            "begin"+

            "<foreach collection='lists' item='data' index='index' separator=';'>" +

            "${sqlStr}"+

            "</foreach>;" +

            "end;"+

            "</script>")
    void insert4(@Param("lists") List<Map<String,Object>> kLines , @Param("sqlStr") String sql);


    @DataSource(DataSourceEnum.DB4)
    @Delete("${sqlStr}")
    void delete4(@Param(value = "sqlStr")String sql);

    @DataSource(DataSourceEnum.DB1)
    @Update("${sqlStr}")
    void update1(@Param(value = "sqlStr")String sql);


    @DataSource(DataSourceEnum.DB4)
    @Update("${sqlStr}")
    void update4(@Param(value = "sqlStr")String sql);


    @DataSource(DataSourceEnum.DB4)
    @Select({
            "<script>",
            "select t.*,100 as updatePercentage ,'success' as updateStatus  from  qx_t_kpi_result t where dept_name ='全院' and  " +
                    " pid in ",
            "<foreach collection='pidList' item='pidList' open='(' separator=',' close=')'>",
            "#{pidList}",
            "</foreach>",
            "</script>"
    })
    List<Map<String,Object>> searchQx_t_kpi_resultList( @Param("pidList") List<String> pidList);



    @DataSource(DataSourceEnum.DB1)
    @Select({
            "<script>",
            "select * from ${tableName} where " +
                    "IFNULL(sql_detail_value,'') not REGEXP '失败' and\n" +
                    "IFNULL(sql_detail_value,'') not REGEXP '未调试' and\n" +
                    "IFNULL(sql_value,'') not REGEXP '失败' and\n" +
                    "IFNULL(sql_value,'') not REGEXP '未调试' and " +
                    "LENGTH(sql_detail)>0 "+
            "</script>"
    })
    List<Map<String,Object>> find_selectlist(@Param("tableName") String tableName);



    @DataSource(DataSourceEnum.DB5)
    @Select({
            "<script>",
            "SELECT table_name, comments,table_name||'('||comments||')' as  table_name_Chinese FROM all_tab_comments WHERE upper(owner)= #{owner} and " +
                    " upper(table_name) in ",
            "<foreach collection='tablenamelist' item='tablenamelist' open='(' separator=',' close=')'>",
            "#{tablenamelist}",
            "</foreach>",
            "</script>"
    })
    List<Map<String,Object>> searchtablename( @Param("tablenamelist") List<String> tablenamelist , @Param("owner") String owner);





}